<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>罚息减免</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">已选减免金额合计(元)</div>
                    <div class="field">
                        <input name=vfAmt id="vfAmt" type="text" class="ui-textbox" validate="{required:true,number:true}" value="${vfAmt}" readonly>
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="applyReduBtn" class="sq-button-round">申请减免</span>
                    <span id="saveBtn" class="sq-button-round" style="display:none;">保存</span>
                    <span id="exportFineBtn" class="sq-button-round">导出罚息明细</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,detailGrid=null,ctrlKey=null;
    $(function () {
        ctrlKey='${ctrlKey}';
        vfId='${vfId}';//减免罚息流程业务主键ID
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capOverdueInfo/initOvdPayList.do?cstId=${cstId}&vfId=${vfId}',
            method: 'get',
            columns: [
                {display: '支付表号', name: 'paySchNo', minWidth: 100, align: 'left', enabledSort: false,},
                {display: '所属机构', name: 'buOrgCdNm', minWidth: 100, align: 'left', enabledSort: false,},
                {display: '逾期期数', name: 'payPd', minWidth: 100, align: 'right', enabledSort: false,},
                {display: '逾期天数', name: 'overdueDay', minWidth: 100, align: 'right', enabledSort: false,},
                {display: '罚息总金额', name: 'penaltyAmount', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(value){
                            return '&yen;'+FormatMoney(rowdata.penaltyAmount/100);
                        }
                    }
                },
                {display: '应收总金额', name: 'recAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(value){
                            return '&yen;'+FormatMoney(rowdata.recAmt/100);
                        }
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function ()
            {
                var grid = this;
                grid.collapsedRows = [];
            },
            onAfterShowData:function(){
                /*需不需要展开第一行*/
                if(ctrlKey>0){
                    this.extendDetail(0);
                }
            },
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        liger.get(vfAmt).setReadonly(true);
        if(ctrlKey>0){
            $("#applyReduBtn").hide();
            $("#saveBtn").show();
            if(ctrlKey==2){
                liger.get(vfAmt).setReadonly(false);
            }
        }else{
            $("#saveBtn").hide();
            $("#applyReduBtn").show();
        }

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "*Cd": " "
            });
        });

        var callback = function () {
            grid.reload();
        };

        /* 减免申请 */
        $("#applyReduBtn").click(function (event) {
            var selectedRows = detailGrid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            $.ligerDialog.confirm("是否确认发起罚息减免流程?", function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {id:selectedRows[0].id},
                    url: '<%=path%>/capital/capFund/reduFineApply.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success",SQ_showButtons : true,});
                            Remove_navTab();
                            //回调刷新列表
                            var callback=frameElement.W2W.callback;
                            callback();
                        } else {
                            top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error",SQ_showButtons : true,});
                        }
                    }
                });
            });
        });

        //保存
        $("#saveBtn").click(function (event) {
            var selectedRows = detailGrid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {'id':selectedRows[0].id,'vfId':vfId,'vfAmt':$("#vfAmt").val()},
                url: '<%=path%>/capital/capFund/reduFineApply.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        Remove_navTab();
                        //回调刷新列表
                        var callback=frameElement.W2W.callback;
                        callback();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });

        });

        /* 修改 */
        $("#exportFineBtn").click(function (event) {

        });

    });

    function showDetail_grid(row, detailPanel, callback){
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 5);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/capital/capOverdueInfo/initOvdPayDtlList.do?paySchId='+row.paySchId,
            method: 'get',
            columns: [
                /*{display: 'id', name: 'dataStatusCd', minWidth: 100,align: 'center'},*/
                {display: '罚息日期', name: 'createDate', minWidth: 100,align: 'center',render:renderDate},
                {display: '逾期款项', name: 'feeTypCdNm', minWidth: 100,align: 'center',
                    render:function(rowdata,index,value){
                        return '第'+rowdata.payPd+'期租金';
                    }
                },
                {display: '罚息总金额', name: 'penaltyAmount', minWidth: 100 ,align: 'right',
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.penaltyAmount/100);
                    }
                },
                {display: '应收总金额', name: '', minWidth: 100,align: 'right',
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney((rowdata.penaltyAmount+rowdata.overdueAmount)/100);
                    }
                },
                {display: '实收罚息金额', name: 'payAmount', minWidth: 100,align: 'right',
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.payAmount/100);
                    }
                },
            ],
            onSelectRow: function (rowdata, rowindex) {
                $("#vfAmt").val(FormatMoney(rowdata.penaltyAmount/100));
            },
            isDisabledSelect: function (item) {
                if(ctrlKey>1){
                    item.dataStatusCd=0;
                }
                if(item.dataStatusCd == '0'){
                    return true;
                }
            },
            isChecked:function(item){
                if(ctrlKey>0 && row.id==item.id){
                   return true;
                }
            },
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            heightDiff: -2,
            isScroll: false,
            //rownumbers: true,
            checkbox:true,
            allowUnSelectRow: true,
            alternatingRow: true,
            isSingleCheck:true,
            onAfterShowData: callback,
            frozen: false,
        });
    }

    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    /* 导出 */
    $("#exportFineBtn").click(function (event) {
        window.location.href="<%=path%>/risk/ovdCollect/exportFineList.do?cstId=${cstId}";
    });

</script>

</body>
</html>
